package com.yike.user.controller;

import com.yike.user.entity.ShopUser;
import com.yike.user.service.ShopUserService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.ShopUserPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 店铺用户表 控制器
 *
 * @author Sakura
 * @since 2024-08-26
 */
@Slf4j
@RestController
@RequestMapping("/shopUser")
@Module("user")
@Api(value = "店铺用户表API", tags = {"店铺用户表"})
@ApiIgnore // 暂时不显示到文档
public class ShopUserController extends BaseController {

    @Autowired
    private ShopUserService shopUserService;

    /**
     * 添加店铺用户表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加店铺用户表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加店铺用户表", response = ApiResult.class)
    public ApiResult<Boolean> addShopUser(@Validated(Add.class) @RequestBody ShopUser shopUser) throws Exception {
        boolean flag = shopUserService.saveShopUser(shopUser);
        return ApiResult.result(flag);
    }

    /**
     * 修改店铺用户表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改店铺用户表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改店铺用户表", response = ApiResult.class)
    public ApiResult<Boolean> updateShopUser(@Validated(Update.class) @RequestBody ShopUser shopUser) throws Exception {
        boolean flag = shopUserService.updateShopUser(shopUser);
        return ApiResult.result(flag);
    }

    /**
     * 删除店铺用户表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除店铺用户表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除店铺用户表", response = ApiResult.class)
    public ApiResult<Boolean> deleteShopUser(@PathVariable("id") Long id) throws Exception {
        boolean flag = shopUserService.deleteShopUser(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取店铺用户表详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "店铺用户表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "店铺用户表详情", response = ShopUser.class)
    public ApiResult<ShopUser> getShopUser(@PathVariable("id") Long id) throws Exception {
        ShopUser shopUser = shopUserService.getById(id);
        return ApiResult.ok(shopUser);
    }

    /**
     * 店铺用户表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "店铺用户表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "店铺用户表分页列表", response = ShopUser.class)
    public ApiResult<Paging<ShopUser>> getShopUserPageList(@Validated @RequestBody ShopUserPageParam shopUserPageParam) throws Exception {
        Paging<ShopUser> paging = shopUserService.getShopUserPageList(shopUserPageParam);
        return ApiResult.ok(paging);
    }

}

